local hx__chongsheng = fk.CreateSkill {
  name = "hx__chongsheng",
}

hx__chongsheng:addEffect(fk.EnterDying, {
  anim_type = "support",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(hx__chongsheng.name) and player:usedSkillTimes(hx__chongsheng.name, Player.HistoryGame) < 2
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if player:isWounded() and not player.dead then
      room:recover({
        who = player,
        num = 3-player.hp,
        recoverBy = player,
        skillName = hx__chongsheng.name
      })
    end
    room:throwCard(player:getCardIds(Player.Hand), hx__chongsheng.name, player, player)
    local tos = room:askToChoosePlayers(player, {
      targets = room:getOtherPlayers(player),
      min_num = 1,
      max_num = 1,
      prompt = "选择一名其他角色，你摸等同于其手牌数张牌并弃置其至多3张牌或获得其区域内至多2张牌）",
      skill_name = hx__chongsheng.name,
      cancelable = true,
    })
    if #tos == 0 then return end
    local to = tos[1]
    if #to:getCardIds(Player.Hand) == 0 then return end
    player:drawCards(#to:getCardIds(Player.Hand), hx__chongsheng.name)
    local choice = room:askToChoice(player, {
      choices = {"弃置其至多3张牌", "获得其区域内至多2张牌"},
      skill_name = hx__chongsheng.name,
    })
    if choice == "弃置其至多3张牌" then
      local card = room:askToChooseCards(player, {
        target = to,
        min = 1,
        max = 3,
        flag = "he",
        skill_name = hx__chongsheng.name,
      })
      room:throwCard(card, hx__chongsheng.name, to, player)
    elseif choice == "获得其区域内至多2张牌" then
      local card2 = room:askToChooseCards(player, {
        target = to,
        min = 1,
        max = 2,
        flag = "he",
        skill_name = hx__chongsheng.name,
      })
      room:moveCards{
        ids = card2,
        from = to,
        to = player,
        toArea = Card.PlayerHand,
        moveReason = fk.ReasonJustMove,
        skillName = hx__chongsheng.name,
        proposer = player,
      }
    end
  end,
})

return hx__chongsheng